package com.zlq.cn.util;

import java.util.Random;
import java.util.UUID;

public class StringUtils extends org.apache.commons.lang3.StringUtils {
    public static boolean checkPhone(String phone) {
        if (org.apache.commons.lang3.StringUtils.isEmpty(phone)) {
            return false;
        }
        if (phone.length() < 11) {
            return false;
        }
        return org.apache.commons.lang3.StringUtils.isNumeric(phone);
    }

    public static boolean checkVcode(String vcode) {
        if (org.apache.commons.lang3.StringUtils.isEmpty(vcode)) {
            return false;
        }
        if (vcode.length() != 4) {
            return false;
        }
        return org.apache.commons.lang3.StringUtils.isNumeric(vcode);
    }

    /**
     * 取得规定位数的随机数
     *
     * @param length
     * @return
     */
    public static String getRandomByLength(int length) {
        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        while (sb.length() < length) {
            int i = random.nextInt(10);
            if (i > 0) {
                sb.append(i);
            }
        }
        return sb.toString();
    }

    public static String createToken() {
        return UUID.randomUUID().toString().replace("-", "");
    }

    public static String iphoneModel(String platform) {
        if ("x86_64".equals(platform)) {
            return "iPhone simulator";
        } else if ("iPhone1,1".equals(platform)) {
            return "iPhone";
        } else if ("iPhone1,2".equals(platform)) {
            return "iPhone 3G";
        } else if ("iPhone2,1".equals(platform)) {
            return "iPhone 3GS";
        } else if ("iPhone3,1".equals(platform) || "iPhone3,2".equals(platform) || "iPhone3,3".equals(platform)) {
            return "iPhone 4";
        } else if ("iPhone4,1".equals(platform)) {
            return "iPhone 4S";
        } else if ("iPhone5,1".equals(platform) || "iPhone5,2".equals(platform)) {
            return "iPhone 5";
        } else if ("iPhone5,3".equals(platform) || "iPhone5,4".equals(platform)) {
            return "iPhone 5C";
        } else if ("iPhone6,2".equals(platform) || "iPhone6,1".equals(platform)) {
            return "iPhone 5S";
        } else if ("iPhone7,2".equals(platform)) {
            return "iPhone 6";
        } else if ("iPhone7,1".equals(platform)) {
            return "iPhone 6 Plus";
        } else if ("iPhone8,1".equals(platform)) {
            return "iPhone 6S";
        } else if ("iPhone8,2".equals(platform)) {
            return "iPhone 6S Plus";
        } else if ("iPhone8,3".equals(platform) || "iPhone8,4".equals(platform)) {
            return "iPhoneSE";
        } else if ("iPhone9,1".equals(platform) || "iPhone9,3".equals(platform)) {
            return "iPhone 7";
        } else if ("iPhone9,2".equals(platform) || "iPhone9,4".equals(platform)) {
            return "iPhone 7 Plus";
        } else if ("iPhone10,1".equals(platform) || "iPhone10,4".equals(platform)) {
            return "iPhone 8";
        } else if ("iPhone10,2".equals(platform) || "iPhone10,5".equals(platform)) {
            return "iPhone 8 Plus";
        } else if ("iPhone10,3".equals(platform) || "iPhone10,6".equals(platform)) {
            return "iPhone X";
        } else if ("iPhone11,2".equals(platform)) {
            return "iPhone XS";
        } else if ("iPhone11,4".equals(platform) || "iPhone11,6".equals(platform)) {
            return "iPhone XS Max";
        } else if ("iPhone11,8".equals(platform)) {
            return "iPhone XR";
        } else if ("iPhone12,1".equals(platform) || "iPhone12,5".equals(platform)) {
            return "iPhone 11 Pro";
        } else if ("iPhone12,3".equals(platform)) {
            return "iPhone 11";
        }
        return "iPhone";
    }
}
